package com.sky.controller.user;


import com.sky.constant.StatusConstant;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealDishServicr;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userSetMealController")
@RequestMapping("/user/setmeal")
@Api(tags = "套餐浏览接口")
@Slf4j
public class SetMealController {

    @Autowired
    private SetmealService setmealService;


    /**
     * 条件查询
     *
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("C端-套餐浏览接口")
    public Result< List<SetmealVO>> list(@RequestParam Long categoryId) {
        Setmeal setmeal=Setmeal.builder().status(StatusConstant.ENABLE).categoryId(categoryId).build();


        List<SetmealVO> setmealVO= setmealService.seleteByCategoryId(categoryId);
        return Result.success(setmealVO);

    }
    /**
     * 根据套餐id查询包含的菜品列表
     *
     * @param id
     * @return
     */
    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id查询包含的菜品列表")

    @Cacheable(cacheNames = "setmealCache",key = "#categoryId") //key: setmealCache::100
    public Result bysetmealIdGetdish(@PathVariable Long id){

        List<DishItemVO> dishItemVOS=  setmealService.bysetmealIdGetdish(id);

       return Result.success(dishItemVOS);

    }


}
